# -*- coding: utf-8 -*-
# @Time    : 2024/8/30 10:59
# @Author  : qd
# @Email   : 1518603573@qq.com
# @File    : product_page.py
# @Software: PyCharm
from selenium.webdriver.common.by import By
from selenium.webdriver.common.alert import Alert
from pages.base_page import BasePage
"""产品页面"""
class ProductPage(BasePage):
    url="/crm/index.php?m=product"
    """添加产品定位器"""
    product_add_locator = (By.CSS_SELECTOR, "body > div.container > div.row > div:nth-child(2) > div.pull-right > a")
    """关键词输入框定位器"""
    input_keywords_locator = (By.ID, "search")
    """搜索按钮定位器"""
    btn_search_locator = (By.ID, "dosearch")
    """产品1定位器"""
    btn_product_locator = (By.NAME, "product_id[]")
    """产品2定位器"""
    btn_product2_locator = (By.CSS_SELECTOR, "#form1 > table > tbody > tr:nth-child(2) > td:nth-child(1) > input")
    """所有产品的定位器"""
    btn_all_product_locator = (By.ID, "check_all")
    """删除按钮定位器"""
    btn_product_delete_locator=(By.ID,"delete")
    """断言使用的产品名称定位器"""
    product_name_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(1) > td:nth-child(3) > a > span")
    """断言使用的产品名称定位器"""
    product_name2_locator=(By.CSS_SELECTOR,"#form1 > table > tbody > tr:nth-child(2) > td:nth-child(1) > input")
    """搜索产品断言"""
    product_request_locator=(By.CSS_SELECTOR,"/html/body/div[5]/div[2]/div[3]/form/table/tbody/tr/td")
    """点击添加产品按钮"""
    def click_product_add(self):
        self.driver.find_element(*self.product_add_locator).click()

    """在搜索框中输入关键词输入"""
    def input_keywords(self,keywords):
        self.driver.find_element(*self.input_keywords_locator).send_keys(keywords)

    """点击搜索按钮"""
    def click_btn_search(self):
        self.driver.find_element(*self.btn_search_locator).click()

    """选中第一个产品"""
    def click_btn_product(self):
        self.driver.find_element(*self.btn_product_locator).click()

    """选中第二个产品"""
    def click_btn_product2(self):
        self.driver.find_element(*self.btn_product2_locator).click()

    """选中所有产品"""
    def click_btn_all_product(self):
        self.driver.find_element(*self.btn_all_product_locator).click()

    """点击删除"""
    def click_btn_delete_product(self):
        self.driver.find_element(*self.btn_product_delete_locator).click()

    """确定警告框"""
    def click_product_alert(self):
        self.driver.switch_to.alert.accept()

    """获取添加后的产品名称"""
    def get_product_name(self):
        return self.driver.find_element(*self.product_name_locator).text.strip()
    """获取添加后的产品名称"""
    def get_product_name2(self):
        return self.driver.find_element(*self.product_name2_locator).text.strip()
    def get_request(self):
        return self.driver.find_element(*self.product_request_locator).text.strip()